﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BingVis.SilverlightClient.Common;
using System.ComponentModel;

namespace BingVis.SilverlightClient.GoogleTransit
{
    public class FareTapLoader : TransitLoaderBase<IFareTap>, IFareTapLoader
    {
        
        public FareTapLoader(IGTFSFile file)
            : base(file)
        {
            
        }

        public override void ProcessItem(ICSVLine line)
        {
            bool processedSuccess = true;
            FareTap tap = null;
            try
            {
                decimal parsedAmount = 0.0M;
                Decimal.TryParse(line[4].Replace("\"", ""), out parsedAmount);
                tap = new FareTap()
                    {
                        Time = DateTime.Parse(line[0].Replace("\"", "")),
                        StopName = line[1].Replace("\"", ""),
                        CardType = line[2].Replace("\"", ""),
                        RouteName = line[3].Replace("\"", ""),
                        Amount = parsedAmount
                    };
            }
            catch
            {
                processedSuccess = false;
            }

            if (processedSuccess)
            {
                Items.Add(tap);
                OnItemLoaded(tap);
            }
        }

        
    }
}
